package com.dawnling.androidutils.ui;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.dawnling.androidutils.R;
import com.dawnling.androidutils.app.MyApplicaition;
import com.dawnling.androidutils.typeface.AppManager;
import com.dawnling.androidutils.typeface.FontUtils;
import com.dawnling.androidutils.typeface.InfoCache;
import com.dawnling.androidutils.typeface.IntentUtils;

/**
 * 动态字体
 */
public class TypefaceActivity extends AppCompatActivity implements View.OnClickListener {

    String[] ttfUrl = new String[]{"http://qiniu.cpstao.top/microsoftyahei.ttf", "http://qiniu.cpstao.top/msyhbd.ttf"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_typeface);
        AppManager.getAppManager().addActivity(this);
        findViewById(R.id.tv1).setOnClickListener(this);
        findViewById(R.id.tv2).setOnClickListener(this);
        findViewById(R.id.tv3).setOnClickListener(this);
        findViewById(R.id.tv4).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv1://本地字体1
                //替换本地assets
                InfoCache.putTypeface("microsoftyahei.ttf");
                FontUtils.getInstance().replaceSystemDefaultFontFromAsset(MyApplicaition.getApp(), InfoCache.getTypeface());
                //关闭应用所有Activity
                AppManager.getAppManager().finishAllActivity();
                //启动 MainActivity
                IntentUtils.toActivity(this, MainActivity.class, true);
                break;
            case R.id.tv2://本地字体2
                InfoCache.putTypeface("msyhbd.ttf");
                FontUtils.getInstance().replaceSystemDefaultFontFromAsset(MyApplicaition.getApp(), InfoCache.getTypeface());
                //关闭应用所有Activity
                AppManager.getAppManager().finishAllActivity();
                //启动 MainActivity
                IntentUtils.toActivity(this, MainActivity.class, true);
                break;
            case R.id.tv3://网络字体1
                break;
            case R.id.tv4://网络字体2
                break;
        }
    }
}
